<script setup>
import { useCategoryStore } from '@/stores/category.js'
const categoryStore = useCategoryStore()

</script>
<template>
	<div class="home-category">
		<ul class="list">
			<li v-for="item in categoryStore.categoryList" :key="item.id" class="category-item">
				<router-link to="/">{{ item.name }}</router-link>
				<router-link v-for="i in item.children.slice(0, 2)" to="/" :key="i.id">{{ i.name }}</router-link>
				<div class="layer">
					<h4>分类推荐 <small>根据您的购买或浏览记录推荐</small></h4>
					<ul>
						<li v-for="i in item.goods" :key="i.id" class="goods-item">
							<RouterLink to="/">
								<img :src="i.picture" alt="" />
								<div class="info">
									<p class="name ellipsis-2">
										{{ i.name }}
									</p>
									<p class="desc ellipsis">{{ i.desc }}</p>
									<p class="price"><i>¥</i>{{ i.price }}</p>
								</div>
							</RouterLink>
						</li>
					</ul>
				</div>
			</li>
		</ul>

	</div>
</template>

<style scoped lang="scss">
.home-category {
	.list {
		height: 500px;
		width: 250px;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: flex-start;
		background: rgba(0, 0, 0, 0.8);
		color: #fff;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 998;

		.category-item {
			width: 250px;
			padding: 16px 0 16px 30px;
			text-align: left;

			&:hover {
				background-color: $xtxColor;
				.layer {
					display: block;
				}
			}

			a {
				color: #fff;
				margin-right: 5px;
			}

			a:first-child {
				font-size: 16px;
			}

			.layer {
				display: none;
				width: 990px;
				height: 500px;
				background: rgba(255, 255, 255, 0.8);
				position: absolute;
				left: 250px;
				top: 0;
				padding-left: 10px;
				color: #000;

				h4 {
					padding: 20px 0;

					small {
						font-weight: normal;
					}
				}

				ul {
					display: flex;
					flex-wrap: wrap;
					justify-content: flex-start;

					// display: none;
					.goods-item {
						width: 310px;
						height: 120px;
						border: 1px solid #eee;
						border-radius: 4px;
						background: #fff;
						margin: 0 10px 10px 0;

						a {
							display: flex;
							align-items: center;
							justify-content: space-between;
							padding: 10px;


							img {
								width: 95px;
								height: 95px;
								margin-right: 10px;
							}

							.info {
								padding-left: 10px;
								line-height: 24px;
								overflow: hidden;

								.name {
									font-size: 16px;
									color: #666;
								}

								.desc {
									color: #999;
								}

								.price {
									font-size: 22px;
									color: $priceColor;
								}
							}
						}
					}
				}
			}
		}

	}
}
</style>